import axios from "axios";

// 文件预加载及缓存
export default async () => {
  const instance = axios.create({
    baseURL: window.location.origin,
  });
  const files = [];
  files.forEach(async (name) => {
    let tag = "cache-file---" + name;
    let target = localStorage.getItem(tag);
    if (!target) {
      try {
        const response = await instance.get(
          window.basePath +
            "/static/externals/" +
            name +
            "?v=" +
            new Date().valueOf()
        );
        target = response.data;
      } catch (error) {
        console.log(error);
      }
    }
    localStorage.setItem(tag, target);
    try {
      eval.call(window, target);
    } catch (error) {
      localStorage.removeItem(tag);
    }
  });
};
